<template>
	<view class="page">
		<view class="price-count-down">
			<view class="price">
				<text class="min">￥</text>
				<text class="max">{{totalPrice}}</text>
				<text class="min">.00</text>
			</view>
			<view class="count-down">
				<view class="title">支付剩余时间</view>
				<view class="count">
					<text class="time">{{hour}}</text>
					<text class="dot">:</text>
					<text class="time">{{min}}</text>
					<text class="dot">:</text>
					<text class="time">{{sec}}</text>
				</view>
			</view>
		</view> 
		<!-- 支付方式列表 -->
		<view class="pay-way">
			<view class="pay-list">
				<view class="list" v-for="(item,index) in PayList" 
				@click="onPayWay(item,index)"
				:key="index">
					<view class="pay-type">
						<image :src="item.icon" mode=""></image>
						<text>{{item.name}}</text>
					</view>
					<view class="check">
						<text class="iconfont" :class="PayWay === index ? 'icon-checked action':'icon-check'"></text>
					</view>
				</view>
			</view>
		</view>
		<view class="pay-submit">
			<view class="submit" @click="onSubmit">{{PayPirce}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				PayList: [
					{
						icon: '/static/zfb_pay.png',
						name: '支付宝支付',
					},{
						icon: '/static/ye_pay.png',
						name: '余额支付',
					},
				],
				PayWay: 0,
				PayPirce: '',
				CountDown: 1000,
				day: 0,
				hour: 0,
				min: 0,
				sec: 0,
				totalPrice:0.00,
				order_no:""
			};
		},
		onLoad(param){
			this.CountDownData();
			this.totalPrice = param.pay_price
			this.order_no = param.order_id
			this.PayPirce = '支付宝支付￥'+this.totalPrice
		},
		watch:{
			PayWay(val, oldVal){
				console.log(val)
				if (val == 0) {
					this.PayPirce = '支付宝支付￥'+this.totalPrice
				}else{
					this.PayPirce = '余额支付'+'￥'+this.totalPrice
				}
			}
		},
		methods:{
			/**
			 * 支付方式切换点击
			 */
			onPayWay(item,index){
				this.PayWay = index;
			},
			/**
			 * 倒计时
			 */
			CountDownData(){
				setTimeout(() =>{
					this.CountDown--;
					this.day = parseInt(this.CountDown / (24*60*60))
					this.hour = parseInt(this.CountDown / (60 * 60) % 24);
					this.min = parseInt(this.CountDown / 60 % 60);
					this.sec = parseInt(this.CountDown % 60);
					if(this.CountDown <= 0){
						return
					}
					this.CountDownData();
				},1000)
			},
			/**
			 * 支付点击
			 */
			onSubmit(){
			  var way = this.PayWay
			  if(way == 0){
				  uni.redirectTo({
				  	url: '/pages/Voice/Voice?order_id='+this.order_no+"&pay_price="+this.totalPrice,
				  })
			  } else if(way == 1){
				  this.$http.get('pay/yue', {
				  	order_no: this.order_no,
					pay_price:this.totalPrice
				  }, {}).then(res => {
				  	console.log(res)
					if(res.data.code  ==  200){
						uni.redirectTo({
							url:'/pages/PayResult/PayResult?order_no='+this.order_no+"&totalPrice="+this.totalPrice
						})
					}else if(res.data.code == 403){
						uni.showModal({
							title:res.data.message,
							 success: function (res) {
							        if (res.confirm) {
							           this.PayWay = res.data.data.index
							           this.totalPrice = res.data.data.price
							        } else if (res.cancel) {
							           uni.navigateBack({
							           	delta:2
							           })
							        }
							    }
						})
					}
				  })
			  }
			
			}
		}
	}
</script>

<style scoped lang="scss">
	@import 'CashierDesk.scss';
</style>
